
#include <OrderedUnits.h>
#include <algorithm>
#include <LengthUnit.h>


OrderedUnits::OrderedUnits()
{
	orderedUnits_m.push_back(&MILE);
	orderedUnits_m.push_back(&YARD);
	orderedUnits_m.push_back(&FEET);
	orderedUnits_m.push_back(&INCH);
}

namespace
{
	bool isGreaterThan(const Unit* lhs, const Unit* rhs)
	{
		return lhs->convertToBaseUnit(1) > rhs->convertToBaseUnit(1);
	}
}


void OrderedUnits::addUnit(const Unit& unit)
{
	orderedUnits_m.push_back(&unit);
//	std::sort( orderedUnits_m.begin(), orderedUnits_m.end(), isGreaterThan);
}



void OrderedUnits::accept( UnitsVisitor* visitor) const
{
	for( UnitList::const_iterator i = orderedUnits_m.begin(); i != orderedUnits_m.end(); i++)
	{
		visitor->visit(*i);
	}
}

const OrderedUnits* OrderedUnits::getOrderedUnits()
{
	static OrderedUnits orderedUnits;
	return &orderedUnits;
}

